<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" %>
<%@ page import="com.bean.Course" %>
<%@ page import="com.jdbc.util.StudentSelectDB" %>
<%@ page import="com.jdbc.util.TimePlanUtil" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎登录在线选课系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/index.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/role.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/table.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/SelectCourseSystem.js"></script>
</head>
<body>
<div class="contain">
    <%@ include file="loginHead.jsp" %>
    <%@ include file="studentNavigate.jsp" %>
    <div class="tableBox">
        <form class="form" action="${pageContext.request.contextPath}/StudentSelectServlet" method="post">
            <table class="table" border="1" cellPadding="10" cellSpacing="0">
                <tr>
                    <th>课程编号</th>
                    <th>课程名称</th>
                    <th>授课教师</th>
                    <th>学分</th>
                    <th>上课时间1</th>
                    <th>上课时间2</th>
                    <th>上课地点</th>
                    <th>总容量</th>
                    <th>选课</th>
                </tr>

                <%
                   // List<Course> course = (List<Course>) request.getAttribute("courses");
                    //用下面这个获取课程信息，不然提示完信息后返回的选课页面表格为空
                    StudentSelectDB db=new StudentSelectDB();
                    db.getConnection();
                    List<Course> course=db.findAllCourses();
                    if (course != null) {
                        for (Course courses : course) {
                %>
                <tr>
                    <td><%=courses.getCourseId()%>
                    </td>
                    <td class="sth"><%=courses.getCourseName()%>
                    </td>
                    <td class="sth"><%=courses.getTeacher()%>
                    </td>
                    <td><%=courses.getPoint()%>
                    </td>
                    <td><%=TimePlanUtil.transform(courses.getTime1())%>
                    </td>
                    <td><%=TimePlanUtil.transform(courses.getTime2())%>
                    </td>
                    <td><%=courses.getLocation()%>
                    </td>
                    <td><%=courses.getLimited()%>
                    </td>
                    <td><input type="checkbox" name="selectCourse" value="<%=courses.getCourseId()%>"></td>
                </tr>
                <%
                        }
                    }
                %>
            </table>
            <div class="selectBtn">
                <button id="selectBtn">选课</button>
            </div>
        </form>
    </div>
</div>
<%
    if (request.getAttribute("selectMessage") != null) {
%>
<script>
    alert("<%=request.getAttribute("selectMessage")%>");
</script>
<%}%>
</body>
</html>